//
//  ChatMessageCellFrame.m
//  搭建框架(代码已封装)
//
//  Created by My Mac on 2017/2/3.
//  Copyright © 2017年 My Mac. All rights reserved.
//

#import "ChatMessageCellFrame.h"
#import "ChatMessages.h"
#import "NSString+TextStringToSize.h"
@implementation ChatMessageCellFrame
-(void)setMessage:(ChatMessages *)message
{
    _message = message;
    //1.屏幕宽度
    CGFloat screenWin = [UIScreen mainScreen].bounds.size.width;
    //2.统一间距
    CGFloat marGin = 5;
    
    //timeFrame
    _timeFrame = CGRectMake(0, 0, screenWin, 15);
    
    //iconFrame
    CGFloat imgY = CGRectGetMaxY(_timeFrame) + marGin;
    CGFloat imgW = 30;
    CGFloat imgH = imgW;
    CGFloat imgX = (message.type == ChatMessagesTypeMe)?(screenWin-imgW-marGin):(marGin);
    _iconFrame = CGRectMake(imgX, imgY, imgW, imgH);
    
    //textBtnFrame
    //设置消息正文的frame 高度、宽度都由正文的内容来决定
    //获取正文的size
    CGSize textSize = [message.text sizeOfTextMaxSize:CGSizeMake(150, MAXFLOAT) font:[UIFont systemFontOfSize:15]];
    CGFloat textBtnY =  CGRectGetMaxY(_iconFrame) - 30;
    CGFloat textBtnW = textSize.width + 50;
    CGFloat textBtnH = textSize.height + 26;
    CGFloat textBtnX = (message.type == ChatMessagesTypeOther)?(CGRectGetMaxX(_iconFrame) + marGin):(screenWin-CGRectGetWidth(_iconFrame)-marGin-textBtnW);
    _textBtnFrame = CGRectMake(textBtnX, textBtnY, textBtnW, textBtnH);
    
    _rowHeight = MAX(CGRectGetMaxY(_iconFrame), CGRectGetMaxY(_textBtnFrame)) + marGin;
}
@end
